﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Messages;
using AutoR.Models;
using AutoR.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;
using Xamarin.Forms;

namespace AutoR.ViewModels.Setting
{
	// Token: 0x0200009D RID: 157
	public class ShipSettingViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x170000BA RID: 186
		// (get) Token: 0x060002E7 RID: 743 RVA: 0x00047D0E File Offset: 0x00045F0E
		// (set) Token: 0x060002E8 RID: 744 RVA: 0x00047D18 File Offset: 0x00045F18
		public UserShip Ship
		{
			[CompilerGenerated]
			get
			{
				return this.<Ship>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Ship>k__BackingField, value))
				{
					return;
				}
				this.<Ship>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Ship);
			}
		}

		// Token: 0x170000BB RID: 187
		// (get) Token: 0x060002E9 RID: 745 RVA: 0x00047D48 File Offset: 0x00045F48
		private INavigationService NavigationService { get; }

		// Token: 0x170000BC RID: 188
		// (get) Token: 0x060002EA RID: 746 RVA: 0x00047D50 File Offset: 0x00045F50
		private IPageDialogService PageDialogService { get; }

		// Token: 0x170000BD RID: 189
		// (get) Token: 0x060002EB RID: 747 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x170000BE RID: 190
		// (get) Token: 0x060002EC RID: 748 RVA: 0x00047D58 File Offset: 0x00045F58
		// (set) Token: 0x060002ED RID: 749 RVA: 0x00047D60 File Offset: 0x00045F60
		public List<UserEquipment> Equip
		{
			[CompilerGenerated]
			get
			{
				return this.<Equip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equip>k__BackingField, value))
				{
					return;
				}
				this.<Equip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equip);
			}
		}

		// Token: 0x170000BF RID: 191
		// (get) Token: 0x060002EE RID: 750 RVA: 0x00047D90 File Offset: 0x00045F90
		// (set) Token: 0x060002EF RID: 751 RVA: 0x00047D98 File Offset: 0x00045F98
		public UserEquipment SelectedItem
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectedItem>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<SelectedItem>k__BackingField, value))
				{
					return;
				}
				this.<SelectedItem>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectedItem);
			}
		}

		// Token: 0x170000C0 RID: 192
		// (get) Token: 0x060002F0 RID: 752 RVA: 0x00047DC8 File Offset: 0x00045FC8
		// (set) Token: 0x060002F1 RID: 753 RVA: 0x00047DD0 File Offset: 0x00045FD0
		public EquipmentConfig SelectEquip
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectEquip>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<SelectEquip>k__BackingField, value))
				{
					return;
				}
				this.<SelectEquip>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectEquip);
			}
		}

		// Token: 0x170000C1 RID: 193
		// (get) Token: 0x060002F2 RID: 754 RVA: 0x00047E00 File Offset: 0x00046000
		// (set) Token: 0x060002F3 RID: 755 RVA: 0x00047E08 File Offset: 0x00046008
		public int SelectPos
		{
			[CompilerGenerated]
			get
			{
				return this.<SelectPos>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<SelectPos>k__BackingField == value)
				{
					return;
				}
				this.<SelectPos>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.SelectPos);
			}
		}

		// Token: 0x170000C2 RID: 194
		// (get) Token: 0x060002F4 RID: 756 RVA: 0x00047E35 File Offset: 0x00046035
		// (set) Token: 0x060002F5 RID: 757 RVA: 0x00047E40 File Offset: 0x00046040
		public EquipmentConfig Equipment1
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment1>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment1>k__BackingField, value))
				{
					return;
				}
				this.<Equipment1>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment1);
			}
		}

		// Token: 0x170000C3 RID: 195
		// (get) Token: 0x060002F6 RID: 758 RVA: 0x00047E70 File Offset: 0x00046070
		// (set) Token: 0x060002F7 RID: 759 RVA: 0x00047E78 File Offset: 0x00046078
		public EquipmentConfig Equipment2
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment2>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment2>k__BackingField, value))
				{
					return;
				}
				this.<Equipment2>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment2);
			}
		}

		// Token: 0x170000C4 RID: 196
		// (get) Token: 0x060002F8 RID: 760 RVA: 0x00047EA8 File Offset: 0x000460A8
		// (set) Token: 0x060002F9 RID: 761 RVA: 0x00047EB0 File Offset: 0x000460B0
		public EquipmentConfig Equipment3
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment3>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment3>k__BackingField, value))
				{
					return;
				}
				this.<Equipment3>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment3);
			}
		}

		// Token: 0x170000C5 RID: 197
		// (get) Token: 0x060002FA RID: 762 RVA: 0x00047EE0 File Offset: 0x000460E0
		// (set) Token: 0x060002FB RID: 763 RVA: 0x00047EE8 File Offset: 0x000460E8
		public EquipmentConfig Equipment4
		{
			[CompilerGenerated]
			get
			{
				return this.<Equipment4>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Equipment4>k__BackingField, value))
				{
					return;
				}
				this.<Equipment4>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Equipment4);
			}
		}

		// Token: 0x170000C6 RID: 198
		// (get) Token: 0x060002FC RID: 764 RVA: 0x00047F18 File Offset: 0x00046118
		public DelegateCommand<string> SelectEquipCommand { get; }

		// Token: 0x170000C7 RID: 199
		// (get) Token: 0x060002FD RID: 765 RVA: 0x00047F20 File Offset: 0x00046120
		public DelegateCommand EquipOKCommand { get; }

		// Token: 0x170000C8 RID: 200
		// (get) Token: 0x060002FE RID: 766 RVA: 0x00047F28 File Offset: 0x00046128
		public DelegateCommand EquipRemoveCommand { get; }

		// Token: 0x170000C9 RID: 201
		// (get) Token: 0x060002FF RID: 767 RVA: 0x00047F30 File Offset: 0x00046130
		public DelegateCommand QuickRepairCommand { get; }

		// Token: 0x170000CA RID: 202
		// (get) Token: 0x06000300 RID: 768 RVA: 0x00047F38 File Offset: 0x00046138
		public DelegateCommand RepairCommand { get; }

		// Token: 0x170000CB RID: 203
		// (get) Token: 0x06000301 RID: 769 RVA: 0x00047F40 File Offset: 0x00046140
		public DelegateCommand SecretaryCommand { get; }

		// Token: 0x170000CC RID: 204
		// (get) Token: 0x06000302 RID: 770 RVA: 0x00047F48 File Offset: 0x00046148
		public DelegateCommand LockCommand { get; }

		// Token: 0x06000303 RID: 771 RVA: 0x00047F50 File Offset: 0x00046150
		public ShipSettingViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.NavigationService = navigationService;
			this.PageDialogService = pageDialogService;
			this.EquipOKCommand = new DelegateCommand(async delegate()
			{
				if (this.SelectEquip != null && this.SelectedItem != null)
				{
					this.Game.DelayTask.ChangeEquipmentQueue.Enqueue(string.Format("{0}|{1}|{2}|0", this.Ship.id, this.SelectedItem.equipmentCid, this.SelectPos));
					await this.PageDialogService.DisplayAlertAsync("提示", "已将换装备请求加入队列", "确定");
				}
			});
			this.EquipRemoveCommand = new DelegateCommand(async delegate()
			{
				if (this.SelectEquip != null && this.SelectEquip.cid != -1)
				{
					this.Game.DelayTask.ChangeEquipmentQueue.Enqueue(string.Format("{0}|{1}|0|1", this.Ship.id, this.SelectPos));
					await this.PageDialogService.DisplayAlertAsync("提示", "已将移除装备请求加入队列", "确定");
				}
			});
			this.SelectEquipCommand = new DelegateCommand<string>(delegate(string s)
			{
				if (this.Ship.Equipment.Count >= Convert.ToInt32(s) + 1)
				{
					this.SelectEquip = this.Ship.Equipment[Convert.ToInt32(s)];
					this.SelectPos = Convert.ToInt32(s);
				}
			});
			this.QuickRepairCommand = new DelegateCommand(async delegate()
			{
				TaskAwaiter<bool> taskAwaiter = this.PageDialogService.DisplayAlertAsync("AutoR", string.Format("快修{0}？", this.Ship.id), "是", "否").GetAwaiter();
				if (!taskAwaiter.IsCompleted)
				{
					await taskAwaiter;
					TaskAwaiter<bool> taskAwaiter2;
					taskAwaiter = taskAwaiter2;
					taskAwaiter2 = default(TaskAwaiter<bool>);
				}
				if (taskAwaiter.GetResult() && !this.Game.DelayTask.QuickBuildQueue.Contains(this.Ship.id))
				{
					this.Game.DelayTask.QuickBuildQueue.Enqueue(this.Ship.id);
				}
			});
			this.RepairCommand = new DelegateCommand(async delegate()
			{
				TaskAwaiter<bool> taskAwaiter = this.PageDialogService.DisplayAlertAsync("AutoR", string.Format("澡堂{0}？", this.Ship.id), "是", "否").GetAwaiter();
				if (!taskAwaiter.IsCompleted)
				{
					await taskAwaiter;
					TaskAwaiter<bool> taskAwaiter2;
					taskAwaiter = taskAwaiter2;
					taskAwaiter2 = default(TaskAwaiter<bool>);
				}
				if (taskAwaiter.GetResult() && !this.Game.RepairTask.RepairQueue.Contains(this.Ship))
				{
					this.Game.RepairTask.RepairQueue.Enqueue(this.Ship);
				}
			});
			this.SecretaryCommand = new DelegateCommand(async delegate()
			{
				TaskAwaiter<bool> taskAwaiter = this.PageDialogService.DisplayAlertAsync("AutoR", string.Format("设置{0}为秘书舰？", this.Ship.id), "是", "否").GetAwaiter();
				if (!taskAwaiter.IsCompleted)
				{
					await taskAwaiter;
					TaskAwaiter<bool> taskAwaiter2;
					taskAwaiter = taskAwaiter2;
					taskAwaiter2 = default(TaskAwaiter<bool>);
				}
				if (taskAwaiter.GetResult() && this.Game.Secretary != this.Ship.id)
				{
					GameData gameData = this.Game;
					gameData.Secretary = await Runtime.Remote.SetSecretary(this.Ship.id);
					gameData = null;
					MessagingCenter.Send<LogMessage>(new LogMessage("更换秘书舰为:" + this.Ship.Name), "Log");
				}
			});
			this.LockCommand = new DelegateCommand(async delegate()
			{
				TaskAwaiter<bool> taskAwaiter = this.PageDialogService.DisplayAlertAsync("AutoR", string.Format("锁定{0}？", this.Ship.id), "是", "否").GetAwaiter();
				if (!taskAwaiter.IsCompleted)
				{
					await taskAwaiter;
					TaskAwaiter<bool> taskAwaiter2;
					taskAwaiter = taskAwaiter2;
					taskAwaiter2 = default(TaskAwaiter<bool>);
				}
				if (taskAwaiter.GetResult() && !this.Ship.isLocked)
				{
					await Runtime.Remote.LockShip(this.Ship.id);
					this.Ship.isLocked = true;
				}
			});
		}

		// Token: 0x06000304 RID: 772 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x06000305 RID: 773 RVA: 0x00048014 File Offset: 0x00046214
		public void OnNavigatedTo(INavigationParameters parameters)
		{
			if (parameters.ContainsKey("ship"))
			{
				this.Ship = (UserShip)parameters["ship"];
				this.Equip = (from i in this.Game.Equipments
				where i.num > 0 && i.ShipType.Contains(this.Ship.Type)
				orderby i.Type, i.Star
				select i).ToList<UserEquipment>();
			}
		}

		// Token: 0x06000306 RID: 774 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}
	}
}
